<?php
class Run extends Spaph_Plugin {
    public function __construct()
    {
        /*** Spaph object ***/
        $spaph = Spaph::getInstance();
        
        $reg   = new Spaph_Reg();
        $reg->set('ERROR_MSG','');
        

        // Run this jalopy
        try {
            $spaph->run();
        }
        catch(Spaph_Not_Found_Exception $e) {
            header('HTTP/1.0 404 Not Found');
            echo('Cannot find page.');
        }
        catch(Lite_Exception $e) {
            // Take care of the view object.
            $this->view = Spaph::getInstance()->view();
            $this->view->message = $e->getMessage();
            $this->view->output('error.tpl.php');      
        }
        catch(Exception $e) {
            foreach(array_reverse(explode("\n",$e->getTraceAsString())) as $t) { error_log($t); }
            error_log($e->getMessage().' in '.$e->getFile().' on line '.$e->getLine());
            header('HTTP/1.0 500 Server Error');
            header('Content-type: text/plain');
            print("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
            print("An error has occurred: ");
            print($e->getMessage());
            print("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        }
    }
}

class Lite_Exception extends Exception { }
